package com.imagination.applet.domain.photo.repository;

import com.imagination.applet.domain.photo.model.UserPhoto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface UserPhotoRepository extends JpaRepository<UserPhoto, Long> {

    List<UserPhoto> queryByUserIdAndDeletedIsFalse(Long userId);

    List<UserPhoto> queryByUserIdAndDeletedIsFalseAndType(Long userId, Integer type);

    @Transactional
    @Modifying
    @Query(value = "Update UserPhoto p set p.deleted = true where p.id = ?1")
    int deleteByPhotoId(Long id);

    @Transactional
    @Modifying
    @Query(value = "Update UserPhoto p set p.deleted = true where p.id in (:idList)")
    int deleteByPhotoId(List<Long> idList);

}
